<?php
	if(count($this->params['pass']) == 0)
	{
		echo $searchForm->create('ListingClaim',array('url'=>"/".$this->params['url']['url'],'class'=>'admin_search claim_search')); 
		$fields = cri("ListingClaim")->getFields("group","search");
		echo $searchForm->inputs(am(array('fieldset'=>false),$fields));
		  echo $searchForm->submit(__("Search"));?><div class="clear"></div></form>
	<?php
	} 
	
		
	function setClaimUsernameLink($listingClaim)
	{
		$html = ClassRegistry::getObject("View")->loaded['html'];
		return $html->link($listingClaim['User']['username'],'/admin/users/view/'.$listingClaim['User']['id']);
	}
	
	function setClaimAssignLink($model,$listingClaim)
	{
		if($listingClaim['ListingClaim']['status'] == ListingClaim::STATUS_ASSIGNED)
		{
			return false;
		}	
		return true;
	}
	function setClaimExplantionFlay($listingClaim)
	{
		$html = ClassRegistry::getObject("View")->loaded['appHtml'];
		return $html->flayText($listingClaim['ListingClaim']['explanation'],50);
	}
	
	function setListinClaimsLink($listingClaim)
	{
		$html = ClassRegistry::getObject("View")->loaded['appHtml'];
		return $html->link($listingClaim['Listing']['title'],array($listingClaim['Listing']['id']),array("title"=>sprintf(__("See all claims for %s"),$listingClaim['Listing']['title'])));
	}
	function setClaimRejectLink($model,$listingClaim)
	{
		if($listingClaim['ListingClaim']['status'] == ListingClaim::STATUS_REJECTED)
		{
			return false;
		}else if($listingClaim['ListingClaim']['status'] == ListingClaim::STATUS_ASSIGNED)
		{
			return array("confirmMessage" => __("Are you sure you wan't to remove this user as owner of this listing?"));
		}
		return true;
	}
	//$index = new IndexHelper();
	$index->setData($listingClaims, "ListingClaim");
	$fields = array(
		array('name'=> __("Name")),
		array('email' => __("Email")),
		array('phone_number' => __("Phone number")),
		array('user' => __("User")),
		array('listing_id'=>__('Listing')),
		'status',
		'explanation',
	);
	$index->sortablefields(array("name",'Listing.title','status'));
	$index->showFields($fields);
	$index->addColumn('listing_id', 'setListinClaimsLink');
	$index->addColumn('user', 'setClaimUsernameLink');
	$index->addColumn('explanation', 'setClaimExplantionFlay');
	$index->setAction(__("Accept"),'/admin/listing_claims/accept/:ListingClaim.id',array(),__("Are you sure you want to assign listing to this user?"),false,'setClaimAssignLink');
	$index->setAction(__("Reject"),'/admin/listing_claims/reject/:ListingClaim.id',array(),null,false,'setClaimRejectLink');
	echo $index->display();
?>